<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <form action="/register" method="post" id="form1">
        <h2>注册账号</h2>
        用户名: <input type="text" name="username"> <br>
        密码：<input type="password" name="pwd"> <br>
        确认密码：<input type="password" id="repwd"> <br>
        <button>注册</button>
    </form>   

    <script>
        let form1 = document.getElementById("form1")
        let username = document.getElementsByName("username")[0]
        let pwd = document.getElementsByName("pwd")[0]
        let repwd = document.getElementById("repwd")
        form1.onsubmit = function(e){
            if(username.value.length < 6) {
                alert("账号不得少于六位")
                e.preventDefault();
                return
            }
            if(pwd.value.length < 6) {
                alert("密码不得少于六位")
                e.preventDefault();
                return
            }
            if (!repwd.value.length) {
                alert("请输入确认密码!")
                e.preventDefault();
                return
            }   
            if (pwd.value !== repwd.value) {
                alert("账号密码不一致")
                e.preventDefault();
                return
            }
        }
    </script>
</body>
</html>